home *** CD-ROM | disk | FTP | other *** search
/ Total Web Page (Professional Suite) / Total Web Page 99.iso / CGI / DOWNLOAD.CGI-S=LINKS&C=TXT&F=LINKS.PL < prev    next >
Perl Script  |  1996-06-03  |  7KB  |  180 lines

  1. #!/usr/local/bin/perl
  2. ##############################################################################
  3. # Free For All Link Page        Version 2.2                                  # 
  4. # Copyright 1996 Matt Wright    mattw@worldwidemart.com                      #
  5. # Created 5/14/95               Last Modified 7/17/96                        #
  6. # Scripts Archive at:           http://www.worldwidemart.com/scripts/        #
  7. ##############################################################################
  8. # COPYRIGHT NOTICE                                                           #
  9. # Copyright 1996 Matthew M. Wright  All Rights Reserved.                     #
  10. #                                                                            #
  11. # Free For All Links may be used and modified free of charge by anyone so    #
  12. # long as this copyright notice and the comments above remain intact.  By    #
  13. # using this this code you agree to indemnify Matthew M. Wright from any     #
  14. # liability that might arise from it's use.                                  #  
  15. #                                                                            #
  16. # Selling the code for this program without prior written consent is         #
  17. # expressly forbidden.  In other words, please ask first before you try and  #
  18. # make money off of my program.                                              #
  19. #                                                                            #
  20. # Obtain permission before redistributing this software over the Internet or #
  21. # in any other medium.    In all cases copyright and header must remain intact.#
  22. ##############################################################################
  23. # Define Variables
  24.  
  25. $filename = "/mnt/web/guide/worldwidemart/scripts/demos/links/links.html";
  26. $linksurl = "http://worldwidemart.com/scripts/demos/links/links.html";
  27. $linkscgi = "http://worldwidemart.com/scripts/cgi-bin/demos/links.cgi";
  28. $linkstitle = "Matt's Script Archive: Free For All Demo";
  29. $database = "/mnt/web/guide/worldwidemart/scripts/demos/links/database.txt";
  30.  
  31. # Done
  32. ##############################################################################
  33.  
  34. # Get the input
  35. read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  36.  
  37. # Split the name-value pairs
  38. @pairs = split(/&/, $buffer);
  39.  
  40. foreach $pair (@pairs) {
  41.    ($name, $value) = split(/=/, $pair);
  42.  
  43.    $value =~ tr/+/ /;
  44.    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  45.    $value =~ s/<([^>]|\n)*>//g;
  46.    $value =~ s/<//g;
  47.    $value =~ s/>//g;
  48.    $FORM{$name} = $value;
  49. }
  50.  
  51. if ($FORM{'url'} eq 'http://' || $FORM{'url'} !~ /^(f|ht)tp:\/\/\w+\.\w+/) { 
  52.    &no_url; 
  53. if (!($FORM{'title'})) {
  54.    &no_title;
  55. }
  56.  
  57. # Enter our tags and sections into an associative array
  58.  
  59. %sections = ("busi","Business","comp","Computers","educ","Education",
  60.          "ente","Entertainment","gove","Government",
  61.          "pers","Personal","misc","Miscellaneous");
  62.  
  63. # Suck previous link file into one big string
  64. open(FILE,"$filename");
  65. @lines = <FILE>;
  66. close(FILE);
  67.  
  68. $i=1;
  69. foreach $line (@lines) {    
  70.     if ($line =~ /\<li\>\<a href\=\"([^\"]+)\">([^<]+)<\/a>/) {
  71.         if ($FORM{'url'} eq $1) {
  72.             &repeat_url;
  73.         }
  74.         $i++;
  75.     }
  76. }
  77.  
  78. # Open Link File to Output
  79. open (FILE,">$filename");
  80.  
  81. foreach $line (@lines) { # For every line in our data
  82.  
  83.    if ($line =~ /<!--time-->/) {
  84.       @months = ('January','February','March','April','May','June',
  85.          'July','August','September','October','November','December');
  86.  
  87.       @days = ('Sunday','Monday','Tuesday','Wednesday','Thursday',
  88.            'Friday','Saturday');
  89.  
  90.       ($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6];
  91.       if ($sec < 10) { $sec = "0$sec"; }
  92.       if ($min < 10) { $min = "0$min"; }
  93.       if ($hour < 10) { $hour = "0$hour"; }
  94.       if ($mday < 10) { $mday = "0$mday"; }
  95.       $date = "on $days[$wday], $months[$mon] $mday, 19$year at $hour:$min:$sec";
  96.       print FILE "<!--time--><b>Last link was added $date</b><hr>\n";
  97.    }
  98.    elsif ($line =~ /<!--number-->/) {
  99.       print FILE "<!--number--><b>There are <i>$i</i> links on this ";
  100.       print FILE "page.</b><br>\n";
  101.    }
  102.    else {
  103.        print FILE $line;
  104.    }
  105.  
  106.    foreach $tag ( keys %sections) { # For every tag 
  107.       if ( ($FORM{'section'} eq $sections{$tag}) && 
  108.          ($line =~ /<!--$tag-->/) ) {
  109.  
  110.          print FILE "<li><a href=\"$FORM{'url'}\">$FORM{'title'}</a>\n"; 
  111.       }
  112.    }
  113. }
  114.  
  115. close (FILE);
  116.  
  117. # Return Link File
  118. print "Location: $linksurl\n\n";
  119.  
  120. if ($database ne '') {
  121.     open (DATABASE,">>$database");
  122.     print DATABASE "$FORM{'url'}\n";
  123.     close(DATABASE);
  124. }
  125.  
  126. sub no_url {
  127.    print "Content-type: text/html\n\n";
  128.    print "<html><head><title>ERROR: No URL</title></head>\n";
  129.    print "<body bgcolor=#FFFFFF text=#000000><center>";
  130.    print "<h1>No URL</h1></center>\n";
  131.    print "You forgot to enter a url you wanted added to the Free for ";  
  132.    print "all link page.  Another possible problem was that your link ";
  133.    print "was invalid.<p>\n";
  134.    print "<form method=POST action=\"$linkscgi\">\n";
  135.    print "<input type=hidden name=\"title\" value=\"$FORM{'title'}\">\n";
  136.    print "<input type=hidden name=\"section\""; 
  137.    print "value=\"$FORM{'section'}\">\n";
  138.    print "URL: <input type=text name=\"url\" size=50><p>\n";
  139.    print "<input type=submit> * <input type=reset>\n";
  140.    print "<hr>\n";
  141.    print "<a href=\"$linksurl\">$linkstitle</a>\n";
  142.    print "</form></body></html>\n";
  143.  
  144.    exit;
  145. }
  146.  
  147. sub no_title {
  148.    print "Content-type: text/html\n\n";
  149.    print "<html><head><title>ERROR: No Title</title></head>\n";
  150.    print "<body bgcolor=#FFFFFF text=#000000><center>";
  151.    print "<h1>No Title</h1></center>\n";
  152.    print "You forgot to enter a title you wanted added to the Free for ";
  153.    print "all link page.  Another possible problem is that you title ";
  154.    print "contained illegal characters.<p>\n";
  155.    print "<form method=POST action=\"$linkscgi\">\n";
  156.    print "<input type=hidden name=\"url\" value=\"$FORM{'url'}\">\n"; 
  157.    print "<input type=hidden name=\"section\"";
  158.    print "value=\"$FORM{'section'}\">\n";
  159.    print "TITLE: <input type=text name=\"title\" size=50><p>\n";
  160.    print "<input type=submit> * <input type=reset>\n";
  161.    print "<hr>\n";
  162.    print "<a href=\"$linksurl\">$linkstitle</a>\n";
  163.    print "</form></body></html>\n";
  164.  
  165.    exit;
  166. }
  167.  
  168. sub repeat_url {
  169.    print "Content-type: text/html\n\n";
  170.    print "<html><head><title>ERROR: Repeat URL</title></head>\n";
  171.    print "<body bgcolor=#FFFFFF text=#000000><center><h1>Repeat URL</h1></center>\n";
  172.    print "Sorry, this URL is already in the Free For All Link Page.\n";
  173.    print "You cannot add this URL to it again.  Sorry.<p>\n";
  174.    print "<a href=\"$linksurl\">$linkstitle</a>";
  175.    print "</body></html>\n";
  176.  
  177.    exit;
  178. }
  179.